#!/usr/local/bin/python
# -*- coding: utf-8 -*-
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect

from django.contrib.auth.decorators import login_required
from django import forms

class BaseForm(forms.Form):
    def process(self):
        raise Exception('Subclass of BaseForm must implement process method')

class TestForm(BaseForm):
    day = forms.DateField(help_text='yyyy-mm-dd',
                          widget=forms.TextInput(attrs={'class': 'vDateField required'}))

@login_required
def generic_form(request, template='generic_form.html', form=TestForm, redirect='home'):
    if request.method == 'POST':
        form = form(request.POST)
        if form.is_valid():
            #form.save()
            data = form.cleaned_data
            form.process()
            return HttpResponseRedirect(redirect)
    else:
        form = form()
    return render_to_response(template, {'form': form})
